package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apiguardian.api.API;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "护理项目相关接口")
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController {

    @Autowired
    NursingProjectService nursingProjectService;

    /**
     * 分页条件查询
     */
    @ApiOperation("分页条件查询")
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> pageQuery(@ApiParam(name = "name", value ="护理项目名称" ) String name,
                                                                    @ApiParam(name = "status", value ="状态 0禁用 1启用" ) Integer status,
                                                                    @ApiParam(name = "pageNum", value ="页码" )
                                                                    @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                                    @ApiParam(name = "pageSize", value ="条数" )
                                                                    @RequestParam(required = false, defaultValue = "10") Integer pageSize){
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.pageQuery(name, status, pageNum, pageSize);
        return ResponseResult.success(pageResponse);
    }
    /**
     * 新增护理项目
     */
    @ApiOperation("新增护理项目")
    @PostMapping
    public ResponseResult addNursingProject(@ApiParam(value = "护理项目dto对象", required = true)
                                            @RequestBody NursingProjectDto dto){
        nursingProjectService.addNursingProject(dto);
        return ResponseResult.success();
    }
    /**
     * 根据id查询护理项目
     */
    @ApiOperation("根据id查询护理项目")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id){
        NursingProjectVo vo = nursingProjectService.getById(id);
        return ResponseResult.success(vo);
    }
    /**
     * 修改护理项目
     */
    @ApiOperation("修改护理项目")
    @PutMapping
    public ResponseResult updateNursingProject(@ApiParam(value = "护理项目dto对象", required = true)
                                               @RequestBody NursingProjectDto dto){
        nursingProjectService.updateNursingProject(dto);
        return ResponseResult.success();
    }
    /**
     * 删除护理项目
     */
    @ApiOperation("删除护理项目")
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@ApiParam(value = "护理项目id", required = true)
                                     @PathVariable Long id){
        nursingProjectService.deleteById(id);
        return ResponseResult.success();
    }
}